package ilog.gauges.percentgauge
{
  import com.PGD.events.TimeLineEvent;
  
  import flash.display.CapsStyle;
  import flash.display.GradientType;
  import flash.display.Graphics;
  import flash.display.JointStyle;
  import flash.geom.Matrix;
  import flash.geom.Rectangle;
  
  import ilog.gauges.rectangular.renderers.MarkerRenderer;
  
  import mx.graphics.IFill;
  import mx.graphics.IStroke;

  public class TriangleMarker extends MarkerRenderer
  {
    public function TriangleMarker()
    {
      super();
      mouseMode="shape";
      thickness=12;
      length=12;
      y=-19;
      editable=true;
      liveDragging=true;
    }

    public var min:Number=-1;
    public var max:Number=101;

	private var _oldVal:Number;
    override public function set value(val:Object):void
    {
      var v:Number=Number(val);
      if (v > min && v < max)
        super.value=val;
       
    }
    override public function mouseUpHandlerImpl(stageX:Number, stageY:Number):void
    {
    	super.mouseUpHandlerImpl(stageX,stageY);
    	
    	if(Number(super.value) != _oldVal)
    	{
    		var evt:TimeLineEvent = new TimeLineEvent(TimeLineEvent.INDICATOR_MOVE_EVENT);
    		evt.currentTime = Number(super.value);
    		dispatchEvent(evt);
    	}
    	_oldVal = Number(super.value)
    	
    } 

    override protected function drawMarker(g:Graphics, horizontal:Boolean, x:Number, y:Number, w:Number, h:Number, fill:IFill, stroke:IStroke):void
    {
      if (fill != null)
      {
        fill.begin(g, new Rectangle(x, y, w, h));
      }

      var m:Matrix=new Matrix();
      m.createGradientBox(w, h, 120, x, y);
      g.lineStyle(1, 0, 1, true, "none", CapsStyle.SQUARE, JointStyle.BEVEL, 4);
      g.lineGradientStyle(GradientType.LINEAR, [0x888888, 0xCECECE, 0x888888], [1, 1, 1], [0, 100, 240], m);


      g.moveTo(x, y);
      g.lineTo(x + w, y);
      g.lineTo(x + w / 2, y + h);
      g.lineTo(x, y);
      if (fill != null)
      {
        fill.end(g);
      }
    }
  }
}
